var t = getApp();

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        page_id: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        coupons_list: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    lifetimes: {
        attached: function() {},
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this.data.datas.list.data ? (this.setData({
            total_page: this.data.datas.list.last_page
        }), this.data.total_page <= this.data.page && this.setData({
            isLoadMore: !1
        }), this.data.datas.list.data.length > this.data.datas.get_number && (this.data.datas.list.data.splice(this.data.datas.get_number, this.data.datas.list.data.length - this.data.datas.get_number), 
        this.setData({
            isLoadMore: !1
        })), this.setData({
            coupons_list: this.data.datas.list.data
        })) : (this.data.datas.list.length <= 0 && this.setData({
            isLoadMore: !1
        }), this.setData({
            coupons_list: this.data.datas.list
        }));
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        selectedcoupon: function(a) {
            var e = this, s = a.currentTarget.dataset.item, o = a.currentTarget.dataset.index;
            if (3 != s.api_availability) {
                var i = t.getNetAddresss("coupon.member-coupon.get-coupon");
                t._postNetWork({
                    url: i,
                    data: {
                        coupon_id: s.id
                    },
                    success: function(t) {
                        var a = t.data;
                        1 == a.result ? (e.data.coupons_list[o] = a.data, e.setData({
                            coupons_list: e.data.coupons_list
                        }), wx.showModal({
                            title: "提示",
                            content: "已领取，可到个人中心--优惠券查看",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageA/member/coupon_v2/coupon_v2"
                                }) : t.cancel;
                            }
                        })) : a.data.reason ? wx.showModal({
                            title: a.msg,
                            content: a.data.reason,
                            showCancel: !1
                        }) : wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1e3
                        });
                    },
                    fail: function(t) {
                        console.log(t.msg);
                    }
                });
            }
        },
        getMoreData: function() {
            var a = this;
            if (a.setData({
                isLoadMore: !1
            }), !(a.data.page >= a.data.total_page || this.data.coupons_list.length > this.data.datas.get_number)) {
                a.setData({
                    page: a.data.page + 1
                });
                var e = t.getNetAddresss("home-page.get-decorate-page");
                e += "&page=" + a.data.page, e += "&decorate_id=" + a.data.page_id, e += "&component_id=" + a.data.component_id, 
                e += "&component_key=U_coupons", t._getNetWork({
                    url: e,
                    success: function(t) {
                        var e = t.data;
                        if (1 == e.result) {
                            a.data.page < a.data.total_page && a.setData({
                                isLoadMore: !0
                            });
                            var s = a.data.coupons_list.concat(e.data.data);
                            s.length > a.data.datas.get_number && (s.splice(a.data.datas.get_number, s.length - a.data.datas.get_number), 
                            a.setData({
                                isLoadMore: !1
                            })), a.setData({
                                coupons_list: s
                            });
                        } else a.setData({
                            page: a.data.page - 1,
                            isLoadMore: !1
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        }
    }
});